//
//  SearchListCell.m
//  MedicineBox
//
//  Created by dllo on 15/9/19.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "SearchListCell.h"
#import "CustomTap.h"
#import "UIImageView+WebCache.h"
#import "DKNightVersion.h"
@interface SearchListCell ()


@property (nonatomic, retain) UILabel *leftStock;
@property (nonatomic, retain) UILabel *rightStock;
@property (nonatomic, retain) CustomTap *leftTap;
@property (nonatomic, retain) UIImageView *leftImage;
@property (nonatomic, retain) UILabel *leftTitle;
@property (nonatomic, retain) UILabel *leftPrice;
@property (nonatomic, retain) CustomTap *rightTap;
@property (nonatomic, retain) UIImageView *rightImage;
@property (nonatomic, retain) UILabel *rightTitle;
@property (nonatomic, retain) UILabel *rightPrice;

@end

@implementation SearchListCell

- (void)dealloc
{
    
    [_leftStock release];
    [_rightStock release];
    [_leftImage release];
    [_leftPrice release];
    [_leftTap release];
    [_leftTitle release];
    [_rightImage release];
    [_rightPrice release];
    [_rightTap release];
    [_rightTitle release];
    [super dealloc];
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
        [self creatSubview];
        
    }
    return self;
}

- (void)creatSubview
{

    self.leftImage = [[UIImageView alloc] initWithFrame:CGRectMake(10 , 5 , (([[UIScreen mainScreen] bounds].size.width - 40) / 2), (([[UIScreen mainScreen] bounds].size.width - 40) / 2))];
    _leftImage.userInteractionEnabled = YES;
    [self.contentView addSubview:_leftImage];
    [_leftImage release];
    
    self.leftTap = [[CustomTap alloc] initWithTarget:self action:@selector(tapAction:)];
    [_leftImage addGestureRecognizer:_leftTap];
    [_leftTap release];
    
    self.leftTitle = [[UILabel alloc] initWithFrame:CGRectMake(_leftImage.frame.origin.x , _leftImage.frame.origin.y + _leftImage.frame.size.height, _leftImage.frame.size.width, 30)];
    _leftTitle.nightTextColor = [UIColor whiteColor];
    self.leftTitle.numberOfLines = 0;
    _leftTitle.textAlignment = NSTextAlignmentCenter;
    _leftTitle.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:_leftTitle];
    [_leftTitle release];
    
    
    self.leftPrice = [[UILabel alloc] initWithFrame:CGRectMake(_leftTitle.frame.origin.x, _leftTitle.frame.origin.y + _leftTitle.frame.size.height, _leftTitle.frame.size.width, 20)];
    _leftPrice.textColor = [UIColor redColor];
    _leftPrice.font = [UIFont fontWithName:@"DevanagariSangamMN-Bold" size:15];
    _leftPrice.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:_leftPrice];
    [_leftPrice release];
    
    
    self.leftStock = [[UILabel alloc] initWithFrame:CGRectMake(_leftPrice.frame.size.width / 2 - 10, 0, 80, 30)];
    self.leftStock.numberOfLines = 0;
    _leftStock.nightTextColor = [UIColor whiteColor];
    _leftStock.textAlignment = NSTextAlignmentRight;
    _leftStock.font = [UIFont systemFontOfSize:10];
    [self.leftPrice addSubview:_leftStock];
    [_leftStock release];
    
    self.rightImage = [[UIImageView alloc] initWithFrame:CGRectMake(_leftImage.frame.origin.x + _leftImage.frame.size.width + 10 , 5, (([[UIScreen mainScreen] bounds].size.width - 40) / 2), (([[UIScreen mainScreen] bounds].size.width - 40) / 2))];
    _rightImage.userInteractionEnabled = YES;
    [self.contentView addSubview:_rightImage];
    [_rightImage release];
    
    self.rightTap = [[CustomTap alloc] initWithTarget:self action:@selector(tapAction:)];
    [_rightImage addGestureRecognizer:_rightTap];
    [_rightTap release];
    
    self.rightTitle = [[UILabel alloc] initWithFrame:CGRectMake(_rightImage.frame.origin.x , _rightImage.frame.origin.y + _rightImage.frame.size.height, _leftTitle.frame.size.width, 30)];
    _rightTitle.nightTextColor = [UIColor whiteColor];
    self.rightTitle.numberOfLines = 0;
    _rightTitle.textAlignment = NSTextAlignmentCenter;
    _rightTitle.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:_rightTitle];
    [_rightTitle release];
    
    self.rightPrice = [[UILabel alloc] initWithFrame:CGRectMake(_rightTitle.frame.origin.x + 10, _rightTitle.frame.origin.y + _rightTitle.frame.size.height, _rightTitle.frame.size.width, 20)];
    _rightPrice.textColor = [UIColor redColor];
    _rightPrice.font = [UIFont fontWithName:@"DevanagariSangamMN-Bold" size:15];
    _rightPrice.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:_rightPrice];
    [_rightPrice release];

    self.rightStock = [[UILabel alloc] initWithFrame:CGRectMake(_rightPrice.frame.size.width / 2 - 10, 0, 80, 30)];
    self.rightStock.numberOfLines = 0;
    _rightStock.nightTextColor = [UIColor whiteColor];
    _rightStock.textAlignment = NSTextAlignmentRight;
    _rightStock.font = [UIFont systemFontOfSize:10];
    [self.rightPrice addSubview:_rightStock];
    [_rightStock release];

}

- (void)tapAction:(CustomTap *)tap
{

    [(NSObject *)self.target performSelector:self.action withObject:tap.dic];

}

- (void)getDic:(NSDictionary *)leftDic dic:(NSDictionary *)rightDic
{

    NSDictionary *tempLeft = [leftDic objectForKey:@"product"];
    NSDictionary *tempRight = [rightDic objectForKey:@"product"];
    _leftTap.dic = leftDic;
    _rightTap.dic = rightDic;
    [_leftImage sd_setImageWithURL:[NSURL URLWithString:[tempLeft objectForKey:@"img"]] placeholderImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"6159c4a3294bc7164b33ea75e3934f86" ofType:@"jpg"]]];
    [_rightImage sd_setImageWithURL:[NSURL URLWithString:[tempRight objectForKey:@"img"]] placeholderImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"6159c4a3294bc7164b33ea75e3934f86" ofType:@"jpg"]]];
    _leftTitle.text = [tempLeft objectForKey:@"name"];
    _rightTitle.text = [tempRight objectForKey:@"name"];
    float leftprice = [[tempLeft objectForKey:@"price"] floatValue];
    _leftPrice.text = [NSString stringWithFormat:@"%.2f元",leftprice];
    float rightPrice = [[tempRight objectForKey:@"price"] floatValue];
    _rightPrice.text = [NSString stringWithFormat:@"%.2f元",rightPrice];
    _leftStock.text = [NSString stringWithFormat:@"库存量:%@",[[tempLeft objectForKey:@"stock"] stringValue]];
    _rightStock.text = [NSString stringWithFormat:@"库存量:%@",[[tempRight objectForKey:@"stock"] stringValue]];

}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
